<?php
session_start();
require "lib/db.php";
require "lib/order-function.php";
require "lib/customer-function.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Order</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
       $("#order").css({"background-color":"#FFF",	
	"color":"#000"});
    });
</script>

<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:2px 3px;
		opacity:0.8;
		text-align:center;
	}

</style>
</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<!--content-->
<div id="content">
<table width="100%" border="1" cellspacing="0">
  <tr>
    <th colspan="7">List Orders</th>
  </tr>
  <tr>
    <th>OrderID</th>
    <th>Customer Name</th>
    <th>Order Year</th>
    <th>Order Month</th>
    <th>Product Number Total</th>
    <th>Order Amount Total(VND)</th>
    <th><a href="add-order.php">Add Order</a></th>
  </tr>
	<?php
    $listorder = getAllOrder();
	while($order = mysql_fetch_array($listorder)){
		$customerID = $order['CustomerID'];
		settype($customerID,"int");
		$customer = mysql_fetch_array(getCustomerByID($customerID));
		ob_start();
    ?>
  <tr>
    <td>{OrderID}</td>
    <td>{CustomerName}</td>
    <td>{OrderYear}</td>
    <td>{OrderMonth}</td>
    <td>{ProductNumberTotal}</td>
    <td>{OrderAmountTotal}</td>
    <td><a href="order-detail.php?orderid={OrderID}">Detail</a> - <a onClick="return confirm('Are you sure delete this order?');" href="delete-order.php?orderid={OrderID}">Delete</a></td>
  </tr>
 	<?php 
	$s = ob_get_clean();
	$s = str_replace("{OrderID}","$order[OrderID]",$s);
	$s = str_replace("{CustomerName}","$customer[CustomerName]",$s);
	$s = str_replace("{OrderYear}","$order[OrderYear]",$s);
	$s = str_replace("{OrderMonth}","$order[OrderMonth]",$s);
	$s = str_replace("{ProductNumberTotal}","$order[ProductNumberTotal]",$s);
	$s = str_replace("{OrderAmountTotal}","$order[OrderAmountTotal]",$s);
	echo $s;
	}
	?>
</table>

</div>

<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>